package com.lianbang.pharmacy.adapter

import cn.ubest.mvvmcore.utils.ResourcesUtils
import cn.ubest.mvvmcore.utils.SpanUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lianbang.pharmacy.R
import com.lianbang.pharmacy.bean.MedicineSupplierListBean

/**
 * Created by maoqi on 2020/11/23.
 */
class MedicineDetailCompanyListAdapter
    : BaseQuickAdapter<MedicineSupplierListBean,
        BaseViewHolder>(R.layout.item_medicine_detail_company_list) {
    override fun convert(helper: BaseViewHolder, item: MedicineSupplierListBean) {
        helper.setText(R.id.tv_company, item.merchant_name)
            .setText(R.id.tv_score, "${item.star_level}")
            .setText(R.id.tv_location, "上海市·浦东区")
            .setText(R.id.tv_remain_count, "库存89")
            .setText(R.id.tv_valid_period, "有效期至：2021.02.28")
        val price = item.price.trim()
        if (price.isNotEmpty()) {
            val spanUtils = SpanUtils()
            if (price.contains(".")) {
                //是否包含小数点
                val split = price.split(".")
                val integerPlace = split[0]
                spanUtils
                    .append("¥")
                    .append("${integerPlace}.")
                    .setFontSize(ResourcesUtils.getDimens(R.dimen.sp_22))
                if (split.size > 1) {
                    val decimalPlace = split[1]
                    spanUtils.append(decimalPlace)
                }
            } else {
                spanUtils.append("¥")
                    .append("price")
                    .setFontSize(ResourcesUtils.getDimens(R.dimen.sp_22))
            }

            helper.setText(
                R.id.tv_price,
                spanUtils.create()
            )
        }

    }

}